<?php
/**
 * CompleXml Framework
 *
 * @category   CompleXml
 * @package    CompleXml_Handler
 * @copyright  Copyright (c) 2008 Andrey Kucherenko
 * @license    New BSD License
 * @version    $Id: Xslt.php 9 2008-11-16 17:58:08Z kucherenko.andrey $
 */
require_once 'CompleXml/Handler/Output/Abstract.php';

class CompleXml_Handler_Output_Xslt extends CompleXml_Handler_Output_Abstract {

	public function execute(CompleXml_Object_Abstract $Object) {
		if (! ($Object instanceof CompleXml_Object_Controller)) {
			throw new CompleXml_Object_Exception ( 'Object not Controller' );
		}
		$xmlString = $Object->View->getXml ();
		$file = $Object->View->getTemplate().'.xsl';
		$xsl = new DomDocument ( );
		$xsl->load ( $file );

		$xml = new DomDocument ( );
		$xml->loadXML ( $xmlString );
		@$xml->xinclude ();

		$proc = new XsltProcessor ( );
		$xsl = $proc->importStylesheet ( $xsl );

		$newDom = $proc->transformToDoc ( $xml );

		$str = $newDom->saveHTML ();

		$Object->Response->nocache ();

		echo $str;

	}
}